$(document).ready(function() {
	 $("#updateBtn").click(function () {
		 if(!checkPassword()){	 
			 $('#to_select_list').each(function(){
				 $('#to_select_list option').attr("selected","selected");
			 });
			 $("#username").removeAttr('disabled');
			 $("form").attr('action',contextRoot+"/userdetails/update.html")
		 }
		 else{
			 return false;
		 }
	 });
	 $("#cancelBtn").click(function () {
		 $("form").attr('method',"GET");		 
		 $("form").attr('action',contextRoot+"/userdetails/view.html")
	 });	 
	 
	});

	function checkUser() {
		$(".error").hide();
		var hasError = false;
		var userName = $("#username").val();
		var passwordVal = $("#password").val();		
		if (userName == "") {
			$("#validation")
					.after(
							'<span class="error" style="color: red">User Name is mandatory.</span>');
			hasError = true;
		}else if (password == "") {
			$("#validation")
			.after(
					'<span class="error" style="color: red">Password is mandatory</span>');
			hasError = true;
		}
		return hasError;
	}
	function checkPassword() {
		$(".error").hide();
		var hasError = false;
		var passwordVal = $("#password").val();
		var checkVal = $("#password-check").val();
		if (passwordVal != checkVal) {
			$("#password-check")
					.after(
							'<span class="error">Passwords do not match.</span>');
			hasError = true;
		}
		return hasError;
	}
	
	//this will move selected items from source list to destination list      
	function move_list_items(sourceid, destinationid)
	{
	  $("#"+sourceid+"  option:selected").appendTo("#"+destinationid);
	}
	 
	//this will move all selected items from source list to destination list
	function move_list_items_all(sourceid, destinationid)
	{
	  $("#"+sourceid+" option").appendTo("#"+destinationid);
	}	